#ifndef MUSICWINDOW_H
#define MUSICWINDOW_H

#include <QMainWindow>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QListWidgetItem>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QMap>

namespace Ui {
class MusicWindow;
}

class MusicWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MusicWindow(QWidget *parent = nullptr);
    ~MusicWindow();
    void updateBtnMode();
    void LocalMusicDatabase();
    void init();

private slots:
    void on_btn_play_clicked();

    void on_btn_load_clicked();

    void on_localList_itemDoubleClicked(QListWidgetItem *item);

    void on_btn_next_clicked();

    void on_btn_pre_clicked();

    void setTotal(qint64 duration);

    void setPosition(qint64 position);

    void on_pushButton_clicked();

    void on_progress_bar_sliderReleased();

    void onlineMusicShow(QNetworkReply *reply);

    void on_onlineList_itemDoubleClicked(QListWidgetItem *item);

private:
    Ui::MusicWindow *ui;
    QMediaPlayer *player;
    QMediaPlaylist *playlist;
    QMediaPlayer *onlineplayer;
    QMediaPlaylist *onlineplaylist;
    int total=0;
    QMap<qint64, QString> lyrics; // 存储时间戳和歌词
    QMap<QString, QString> onlineLrcPaths;  // 存储在线音乐的歌词路径
    void loadLyrics(const QString &path); // 加载歌词文件
    void parseLyrics(const QByteArray &data); // 解析歌词
    void updateLyric(qint64 position); // 更新歌词显示
    void loadOnlineLyrics(const QString &url);  // 加载在线歌词
    QNetworkAccessManager *networkManager;      // 网络管理器
};

#endif // MUSICWINDOW_H
